﻿using System;
using System.IO;
using System.Xml.Serialization;
using Utility;

namespace WallpaperEngine
{
    [Serializable]
    public class Configuration
    {
        [XmlAttribute]
        public bool AllowMouseHook { get; set; }

        [XmlAttribute]
        public bool AllowShellTrayTransparency { get => ShellTray.AllowTransparency; set { ShellTray.AllowTransparency = value; } }

        [XmlAttribute]
        public string CurrentWallpaper { get; set; }

        public static Configuration Config { get; set; }

        public static void Init()
        {
            if (!File.Exists(PathManager.ConfigPath))
            {
                ShellTray.AllowTransparency = true;
                JsonSerializer.SerializeToFile(new Configuration()
                {
                    AllowMouseHook = false,
                }, PathManager.ConfigPath);
            }
            Config = JsonSerializer.DeserializeFromFile<Configuration>(PathManager.ConfigPath);
        }

        public static void Save() => JsonSerializer.SerializeToFile(Config, PathManager.ConfigPath);
    }
}
